package com.mao.controller;

import com.mao.mapper.UserMapper;
import com.mao.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList = userMapper.queryUserList();
        return userList;
    }

    @GetMapping("/queryById/{id}")
    public User queryById(@PathVariable("id") int id){
        User user = userMapper.queryById(id);
        return user;
    }

    @GetMapping("/addUser")
    public String addUser(User user){
        userMapper.addUser(new User(7,"阿毛","123456"));
        return "add is ok";
    }

    @GetMapping("/updateUser")
    public String updateUser(User user){
        userMapper.updateUser(new User(7,"王明","123450"));
        return "update is ok";
    }

    @GetMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable("id") int id){
        userMapper.deleteUser(id);
        return "delete is ok";
    }

}
